package com.hy.movie.controller;

import com.hy.movie.common.CommonResult;
import com.hy.movie.model.dto.MessageLoginDto;
import com.hy.movie.model.entity.TbOrder;
import com.hy.movie.service.UserService;
import com.hy.movie.service.WeChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/auth")
public class AuthLogin {
    @Autowired
    private UserService userService;
    @Autowired
    private WeChatService weChatService;

    @PostMapping("/messageLogin")
    public CommonResult messageLogin(@RequestBody MessageLoginDto messageLoginDto) {
        return userService.messageLogin(messageLoginDto);
    }

    @PostMapping("/code")
    public CommonResult codeLogin(@RequestBody Map codeMap){
        String code = (String)codeMap.get("code");
        return weChatService.weChatLogin(code);
    }

    @PostMapping("/sendCode")
    public CommonResult sendCode(@RequestBody MessageLoginDto messageLoginDto){
        return userService.sendMessage(messageLoginDto);
    }



    public  String getTimes(Date date){
        String time = Long.toString(date.getTime());
        time=time.substring(0,time.length()-3);
        return time;
    }
}
